home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1998 November: Tool Chest / Dev.CD Nov 98 TC.toast / Sample Code / QuickTime / JPEG Sample / Source / aevt.c next >
Encoding:
C/C++ Source or Header  |  1997-03-05  |  5.0 KB  |  201 lines  |  [TEXT/CWIE]

  1. /*************************************************************************************
  2. #
  3. #        aevt.c
  4. #
  5. #        Apple events handler.
  6. #
  7. #        Author(s):     Michael Marinkovich
  8. #                    marink@apple.com
  9. #
  10. #        Modification History: 
  11. #
  12. #            10/12/95    MWM     Initial coding                     
  13. #
  14. #        Copyright © 1992-96 Apple Computer, Inc., All Rights Reserved
  15. #
  16. #
  17. #        You may incorporate this sample code into your applications without
  18. #        restriction, though the sample code has been provided "AS IS" and the
  19. #        responsibility for its operation is 100% yours.  However, what you are
  20. #        not permitted to do is to redistribute the source as "DSC Sample Code"
  21. #        after having made changes. If you're going to re-distribute the source,
  22. #        we require that you make it clear in the source that the code was
  23. #        descended from Apple Sample Code, but that you've made changes.
  24. #
  25. *************************************************************************************/
  26.  
  27. #include <AppleEvents.h>
  28. #include <Windows.h>
  29.  
  30. #include "App.h"
  31. #include "Proto.h"
  32.  
  33.  
  34. //----------------------------------------------------------------------
  35. //    Globals
  36. //----------------------------------------------------------------------
  37.  
  38. extern Boolean                gDone;
  39. extern AEEventHandlerUPP    gAEOpenAppUPP;
  40. extern AEEventHandlerUPP    gAEQuitAppUPP;
  41. extern AEEventHandlerUPP    gAEOpenDocUPP;
  42. extern AEEventHandlerUPP    gAEPrintDocUPP;
  43.  
  44.  
  45. //----------------------------------------------------------------------
  46. //
  47. //    AEInit - initialize all the core apple events
  48. //
  49. //
  50. //----------------------------------------------------------------------
  51.  
  52. OSErr AEInit(void)
  53. {    
  54.     OSErr        err = noErr;
  55.                     
  56.     // allocate UPPs
  57.     gAEOpenAppUPP = NewAEEventHandlerProc(DoAEOpenApp);
  58.     gAEQuitAppUPP = NewAEEventHandlerProc(DoAEQuitApp);
  59.     gAEOpenDocUPP = NewAEEventHandlerProc(DoAEOpenDoc);
  60.     gAEPrintDocUPP = NewAEEventHandlerProc(DoAEPrintDoc);
  61.  
  62.     if (nil != gAEOpenAppUPP)        //    install auto Open App
  63.         err = AEInstallEventHandler(kCoreEventClass, kAEOpenApplication, 
  64.                                     gAEOpenAppUPP, 0L, false );
  65.                                                     
  66.     if (noErr == err && nil != gAEQuitAppUPP)            // install auto Quit App
  67.         err = AEInstallEventHandler(kCoreEventClass, kAEQuitApplication, 
  68.                                     gAEQuitAppUPP, 0L, false );
  69.         
  70.     if (noErr == err && nil != gAEOpenDocUPP)            // install auto Open Document
  71.         err = AEInstallEventHandler(kCoreEventClass,kAEOpenDocuments,
  72.                                     gAEOpenDocUPP, 0L,false);
  73.         
  74.     if (noErr == err && nil != gAEPrintDocUPP)            // install auto Print Document
  75.         err = AEInstallEventHandler(kCoreEventClass,kAEPrintDocuments,
  76.                                     gAEPrintDocUPP, 0L,false);
  77.                 
  78.     return err;
  79.                                                 
  80. }
  81.  
  82.  
  83. //----------------------------------------------------------------------
  84. //
  85. //    AEDispose - dispose of UPPs 
  86. //
  87. //
  88. //----------------------------------------------------------------------
  89.  
  90. void AEDispose(void)
  91. {
  92.     if (nil != gAEOpenAppUPP)
  93.         DisposeRoutineDescriptor(gAEOpenAppUPP);
  94.  
  95.     if (nil != gAEQuitAppUPP)
  96.         DisposeRoutineDescriptor(gAEQuitAppUPP);
  97.  
  98.     if (nil != gAEOpenDocUPP)
  99.         DisposeRoutineDescriptor(gAEOpenDocUPP);
  100.  
  101.     if (nil != gAEPrintDocUPP)
  102.         DisposeRoutineDescriptor(gAEPrintDocUPP);
  103.         
  104. }
  105.  
  106.  
  107. //----------------------------------------------------------------------
  108. //
  109. //    DoAEOpenApp - called by the Finder at launch time
  110. //
  111. //
  112. //----------------------------------------------------------------------
  113.  
  114. pascal OSErr DoAEOpenApp(AppleEvent *event, AppleEvent reply, long refCon)
  115. {
  116.     #pragma unused( event, reply, refCon )
  117.  
  118.     return noErr;
  119.         
  120. }
  121.  
  122.  
  123. //----------------------------------------------------------------------
  124. //
  125. //     DoAEQuitApp -    called when the Finder asks app to quit
  126. //
  127. //
  128. //----------------------------------------------------------------------
  129.  
  130. pascal OSErr DoAEQuitApp(AppleEvent *event, AppleEvent reply, long refCon)
  131. {
  132.     #pragma unused(event, reply, refCon)
  133.  
  134.     // set the global quit flag
  135.     gDone = true;
  136.     
  137.     return noErr;
  138.         
  139. }
  140.  
  141.  
  142. //----------------------------------------------------------------------
  143. //
  144. //    DoAEOpenDoc - called when the Finder asks app to open a document
  145. //
  146. //
  147. //----------------------------------------------------------------------
  148.  
  149. pascal OSErr DoAEOpenDoc(AppleEvent *event, AppleEvent reply, long refCon)
  150. {    
  151.     #pragma unused(event, reply, refCon)
  152.     
  153.  
  154.     return noErr;
  155.  
  156. }
  157.                 
  158.                                         
  159. //----------------------------------------------------------------------
  160. //
  161. //    DoAEPrintDoc - called when the Finder asks app to print a document
  162. //
  163. //
  164. //----------------------------------------------------------------------
  165.  
  166. pascal OSErr DoAEPrintDoc(AppleEvent *event, AppleEvent reply, long refCon)
  167. {
  168.     #pragma unused(event, reply, refCon)
  169.     
  170.  
  171.     return noErr;
  172.  
  173. }
  174.  
  175.  
  176. //----------------------------------------------------------------------
  177. //
  178. //    GotAEParams - make sure we got proper AE params for an Open 
  179. //                  Document from the Finder
  180. //
  181. //----------------------------------------------------------------------
  182.  
  183. OSErr GotAEParams(AppleEvent *appleEvent)
  184. {
  185.     OSErr            err;
  186.     DescType        type;
  187.     Size            size;
  188.     
  189.     err = AEGetAttributePtr(appleEvent, keyMissedKeywordAttr,
  190.                             typeWildCard, &type, nil, 0, &size);
  191.     
  192.     if (err == errAEDescNotFound)
  193.         return(noErr);
  194.     
  195.     else
  196.         if (err == noErr)
  197.             return(errAEEventNotHandled);
  198.     
  199.     return err;
  200.